﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Web.UI.WebControls;
using BLL;
using Model;
using ZedGraph;

public partial class StatisticData_TimeStatistic_TimeStatisticPR_PRStatisticsbyQuarter : System.Web.UI.Page
{
    Test_PRT t_qt;
    private string timeMonth
    {
        get { return ViewState["timeMonth"].ToString(); }
        set { ViewState["timeMonth"] = value; }
    }

    public StatisticData_TimeStatistic_TimeStatisticPR_PRStatisticsbyQuarter()
    {
        t_qt = new Test_PRT();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindTimeMonth();
        }
    }

    protected void BindTimeMonth()
    {
        Test_QT t_qt = new Test_QT();
        foreach (Time_QInfo t_qi in t_qt.GetTimeY())
            this.DropDownList1.Items.Add(t_qi.DayTime);
    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        timeMonth = this.DropDownList1.SelectedItem.Text.Trim();
        BindQuarterTests();
        this.ZedGraphWeb1.Visible = true;
    }

    protected void BindQuarterTests()
    {
        this.GridView1.DataSource = t_qt.GetQuarter_OPRbyYear(timeMonth);
        this.GridView1.DataBind();
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        BindQuarterTests();
    }

    protected void ZedGraphWeb1_RenderGraph(ZedGraph.Web.ZedGraphWeb webObject, System.Drawing.Graphics g, ZedGraph.MasterPane pane)
    {
        int i = 0;
        int j = 0;
        List<Time_PRInfo> t_qs = (List<Time_PRInfo>)t_qt.GetQuarter_OPRbyYear(timeMonth);

        GraphPane myPane = pane[0];

        myPane.Title.Text = "按日历季统计一次合格率情况";
        myPane.XAxis.Title.Text = "日历季";
        myPane.YAxis.Title.Text = "一次合格率";

        //创建曲线
        PointPairList list = new PointPairList();
        foreach (Time_PRInfo t_q in t_qs)
        {
            double y = (double)t_q.Quantity;
            int x = i;
            i++;
            list.Add(x, y);
        }
        LineItem myCurve = myPane.AddCurve("", list, Color.Green, SymbolType.Square);
        //myCurve.Line.IsSmooth = true;
        //myPane.AddBar("", list, Color.Green);

        string[] labels = new string[t_qs.Count];
        //给x轴上的每一个间隔点加上说明文字
        foreach (Time_PRInfo t_q in t_qs)
        {
            labels[j] = t_q.DayTime;
            j++;
        }

        myPane.XAxis.Scale.TextLabels = labels; //这里设置的是TextLabels属性，所以下面x轴的类型必须也设置为Text   
        //设置x轴的样式
        myPane.XAxis.Type = AxisType.Text;
        MyGraphStyle.BuildLineItem(myCurve);
        MyGraphStyle.BuildbarGraphStyle(myPane);

        pane.AxisChange(g);
    }
}
